<?php
/**
 * @annotate 后台企业管理
 * @group   Admin/Haiyin
 * @author   yachtxiao <fuck@fackyou.org>
 */
class BrandAction extends BaseAction {
	protected $aVerify = array(
   	'index'
  	);//需要验证的方法
	
	public function brand_list(){
		$this->assign('Title',"品牌列表");
		$timetoday = strtotime(date("Y-m-d",time()));//今天0点的时间点
		$timeyestoday = $timetoday - 3600*24;//今天0点的时间点，两个值之间即为昨
		$map['is_del'] = 0;
		if ($this->isPost()){
			$name = $_POST['brand_name'];
			$map['brand_name'] = array('like',$name);
		}
		$day = $_GET['day'];
		if($day=='today'){
			$map['updateline'] = array('egt',$timetoday);
		}elseif($day=='yesterday'){
			$map['updateline'] = array('between',$timeyestoday.','.$timetoday);
		}
		$list = D('Brand')->select_list($map);
		$this->assign('list',$list);
		$this->display();
	}
	public function not_pass(){
		$this->assign('Title',"未审核品牌列表");
		$map['is_del'] = 0;
		$map['brand_status'] = 0;
		if ($this->isPost()){
			$name = $_POST['brand_name'];
			$map['brand_name'] = array('like',$name);
		}
		$list = D('Brand')->select_list($map);
		$this->assign('list',$list);
		$this->display();
	}
	
	public function del_brand(){
		$map['bid'] = $_POST['id'];
		$data['is_del'] = 1;
		$da = D('brand')->where($map)->save($data);
		if($da){
			$this->ajaxReturn('','success',1);
		}else{
			$this->ajaxReturn('','error',0);
		}
	}
	public function edit_status(){
		$map['bid'] = $_POST['id'];
		$data['brand_status'] = $_POST['val'];
		$da = D('brand')->where($map)->save($data);
		if($da){
			$this->ajaxReturn('','success',1);
		}else{
			$this->ajaxReturn('','error',0);
		}
	}
	public function add_brand(){
		if ($this->isPost()){
			$aid = upload_img_one('brand',$_FILES['brand_ico']);
			$data = array(
						'brand_name' => $_POST['brand_name'],
						'brand_ico' => $aid,
						'brand_intro' => $_POST['brand_intro'],
						'brand_status' => 1,
						'updateline' => time()
					);
			$result = D('Brand')->add_brand($data);
			if($result){
				$this->success("提交成功!");
			}else{
				$this->error('新增失败');
			}
		}
		$this->display();
	}
	public function edit_brand(){
		$map['bid'] = $_GET['bid'];
		$list = D('brand')->where($map)->find();
		$list['url'] = get_img_url($list['brand_ico']);
		$this->assign('list',$list);
		if ($this->isPost()){
			$da['bid'] = $_POST['bid'];
			if(!empty($_POST['brand_ico'])){
				$aid = upload_img_one('brand',$_FILES['brand_ico']);
				$data['brand_ico'] = $aid;
			}
			$data['brand_name'] = $_POST['brand_name'];
			$data['brand_intro'] = $_POST['brand_intro'];
			$data['updateline'] = time();
					
			$result = D('brand')->where($da)->save($data);
			if($result){
				$this->success("修改成功!");
			}else{
				$this->error('修改失败');
			}
		}
		$this->display();
	}
}
?>